<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //参数为一个数组(实际上是iterable类型)
        //返回值默认为一个pending状态的promise实例
        //当所有的promise执行完成后,返回fulfilling状态,值为每个promise实例的值
        //当其中有一个promise实例的状态为失败,返回一个失败的promise实例,值为promise失败的值
        let p1 = new Promise((resolve,reject)=>{
            try {
                console.log('获取A');
                // throw new Error('A错误')
                setTimeout(() => {
                    resolve('A成功')
                }, 1500);
            } catch (e) {
                console.log(e.massage);
            }
        })
        let p2 = new Promise((resolve,reject)=>{
            try {
                console.log('获取B');
                // throw new Error('B错误')
                setTimeout(() => {
                    resolve('B成功')
                }, 2500);
            } catch (e) {
                console.log(e.massage);
            }
        })
        let p3 = new Promise((resolve,reject)=>{
            try {
                console.log('获取C');
                // throw new Error('C错误')
                setTimeout(() => {
                    resolve("C成功")
                }, 2000);
            } catch (e) {
                console.log(e.massage);
            }
        })

        let result= Promise.all([p1,p2,p3])
        console.log(result);
        result.then(resolve=>{
            console.log('成功');
        }).catch(err=>{
            console.log('失败');
        })
    </script>
</body>
</html>